# python 条件语句 与 循环语句

# if...elif...else...
a = input("请输入你的体重:")
a = int(a)
if a > 80:
    print("不减了,开摆~")
elif a > 60:
    print("两餐素食,每天健身三小时~")
elif a > 50:
    print("每天健身两小时~")
elif a > 45:
    print("每天健身一小时~")
elif a > 40:
    print("每天晨跑半小时~")
else:
    print("stop~")

# 三元表达式
# 条件表达式为真时的结果 if 条件表达式 else 条件表达式为假时的结果
print(1 if 12 > 1 else 0)
print(1 if 12 > 15 else 0)

# while 循环
count = 0
while count < 5:
    print("The count is :", count)
    count += 1

print("stop~")

# continue/break
i = 1
while i < 10:
    i += 1
    if i % 2 == 0:
        continue
    print(i)

j = 5
while True:
    print(j)
    j += 2
    if j > 10:
        break

print("======== while 循环中使用 else =======")
# else 的作用:用于判断循环是否是正常结束的,如果循环是由break中断的,则else语句块不会被执行
count = 0
while count < 5:
    print(count, "is less than 5")
    count += 1
else:
    print(count, "is not less than 5")


# for 循环
print("==== for 循环遍历字符串 ====")
for letter in 'Python':
    print("当前字母:", letter)

print("==== for 循环变量列表 ====")
fruits = ['apple', 'banana', 'pear']
for fruit in fruits:
    print("当前水果:", fruit)

print("==== for 循环通过下标遍历列表 ====")
for i in range(len(fruits)):
    print("当前水果:", fruits[i])

print("==== for 循环中使用 else ====")
# else 的作用:用于判断循环是否是正常结束的,如果循环是由break中断的,则else语句块不会被执行
# 计算 10 ~ 20 的 素数
for num in range(10,21):
    for i in range(2, num):
        if num % i == 0:
            j = num / i
            print("%d 等于 %d * %d" % (num, i, j))
            break
    else:
        print(num,'是一个素数')

# 计算 100 以内的素数
prime = []
for num in range(2, 100):
    for i in range(2, num):
        if num % i == 0:
            break
    else:
        prime.append(num)
print(prime)

# continue 的例子
for letter in 'Python':
    if letter == 'h':
        continue
    print(letter)

value = 1
while value < 20:
    value += 1
    if value % 3 == 0:
        continue
    print(value)
